<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="订单ID" prop="orderId">
        <el-input
          v-model="queryParams.orderId"
          placeholder="请输入订单ID"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="熔覆人员" prop="claddingPeople">
        <el-select v-model="queryParams.claddingPeople" placeholder="请选择熔覆人员" clearable size="small">
          <el-option
            v-for="dict in dict.type.zs_cladding_people"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="熔覆名称" prop="claddingName">
        <el-input
          v-model="queryParams.claddingName"
          placeholder="请输入熔覆名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="设备状态" prop="deviceStatus">
        <el-select v-model="queryParams.deviceStatus" placeholder="请选择设备状态" clearable size="small">
          <el-option
            v-for="dict in dict.type.sys_device_status"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="是否处理" prop="isHandle">
        <el-select v-model="queryParams.isHandle" placeholder="请选择是否处理" clearable size="small">
          <el-option
            v-for="dict in dict.type.sys_is_handling"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
<!--      <el-form-item label="是否合格" prop="isqualitified">-->
<!--        <el-select v-model="queryParams.isqualitified" placeholder="请选择是否合格" clearable size="small">-->
<!--          <el-option-->
<!--            v-for="dict in dict.type.sys_quality_result"-->
<!--            :key="dict.value"-->
<!--            :label="dict.label"-->
<!--            :value="dict.value"-->
<!--          />-->
<!--        </el-select>-->
<!--      </el-form-item>-->
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="primary"-->
<!--          plain-->
<!--          icon="el-icon-plus"-->
<!--          size="mini"-->
<!--          @click="handleAdd"-->
<!--          v-hasPermi="['cmelasercladding:cmelasercladding:add']"-->
<!--        >新增</el-button>-->
<!--      </el-col>-->
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['cmelasercladding:cmelasercladding:edit']"
        >修改</el-button>
      </el-col>
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="danger"-->
<!--          plain-->
<!--          icon="el-icon-delete"-->
<!--          size="mini"-->
<!--          :disabled="multiple"-->
<!--          @click="handleDelete"-->
<!--          v-hasPermi="['cmelasercladding:cmelasercladding:remove']"-->
<!--        >删除</el-button>-->
<!--      </el-col>-->
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="warning"-->
<!--          plain-->
<!--          icon="el-icon-download"-->
<!--          size="mini"-->
<!--          @click="handleExport"-->
<!--          v-hasPermi="['cmelasercladding:cmelasercladding:export']"-->
<!--        >导出</el-button>-->
<!--      </el-col>-->
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="cmelasercladdingList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="熔覆处理ID" align="center" prop="id" />
      <el-table-column label="订单ID" align="center" prop="orderId" />
      <el-table-column label="熔覆人员" align="center" prop="claddingPeople">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.zs_cladding_people" :value="scope.row.claddingPeople"/>
        </template>
      </el-table-column>
      <el-table-column label="熔覆名称" align="center" prop="claddingName" />
      <el-table-column label="熔覆类型" align="center" prop="claddingType" />
      <el-table-column label="熔覆工艺" align="center" prop="claddingTech" />
      <el-table-column label="设备状态" align="center" prop="deviceStatus">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_device_status" :value="scope.row.deviceStatus"/>
        </template>
      </el-table-column>
      <el-table-column label="质检记录" align="center" prop="qualityRecord" width="500"/>
      <el-table-column label="是否处理" align="center" prop="isHandle">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_is_handling" :value="scope.row.isHandle"/>
        </template>
      </el-table-column>
      <el-table-column label="是否合格" align="center" prop="isqualitified">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_quality_result" :value="scope.row.isqualitified"/>
        </template>
      </el-table-column>
      <el-table-column label="异常记录" align="center" prop="unnormalRecord" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['cmenonmetal:postprocess:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-view"
            @click="todetail2(scope.row)"
          >详情</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改cmelasercladding对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="订单ID" prop="orderId">
          <el-input v-model="form.orderId" placeholder="请输入订单ID"  :disabled="true"/>
        </el-form-item>
        <el-form-item label="熔覆人员">
          <el-radio-group v-model="form.claddingPeople">
            <el-radio
              v-for="dict in dict.type.zs_cladding_people"
              :key="dict.value"
:label="dict.value"
            >{{dict.label}}</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="熔覆名称" prop="claddingName">
          <el-input v-model="form.claddingName" placeholder="请输入熔覆名称" />
        </el-form-item>
        <el-form-item label="熔覆工艺" prop="claddingTech">
          <el-input v-model="form.claddingTech" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="设备状态">
          <el-radio-group v-model="form.deviceStatus">
            <el-radio
              v-for="dict in dict.type.sys_device_status"
              :key="dict.value"
:label="parseInt(dict.value)"
            >{{dict.label}}</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="质检记录" prop="qualityRecord">
          <el-input v-model="form.qualityRecord" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="是否处理">
          <el-radio-group v-model="form.isHandle">
            <el-radio
              v-for="dict in dict.type.sys_is_handling"
              :key="dict.value"
:label="parseInt(dict.value)"
            >{{dict.label}}</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="是否合格">
          <el-radio-group v-model="form.isqualitified">
            <el-radio
              v-for="dict in dict.type.sys_quality_result"
              :key="dict.value"
:label="parseInt(dict.value)"
            >{{dict.label}}</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="异常记录" prop="unnormalRecord">
          <el-input v-model="form.unnormalRecord" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="上传">
          <!--<file-upload/>-->
          <cladding-process :orderid="form.orderId"  />
        </el-form-item>
        <el-form-item label="下载">
          <el-link   :underline="false">
            <el-button type="primary" @click="getcladdingprocessfile">获取文件<i class="el-icon-download el-icon--right"></i></el-button>
          </el-link>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listCmelasercladding, getCmelasercladding, delCmelasercladding, addCmelasercladding, updateCmelasercladding } from "@/api/cmelasercladding/cmelasercladding";
import ElFormItem from "element-ui/packages/form/src/form-item";
import CladdingProcess from "@/views/cmelasercladding/file/CladdingProcess";
import FileUpload from "@/views/cmelasercladding/file/FileUpload"
import {download} from "@/utils/request";
import {getFileInformation, listCmelasercladding1} from "@/api/cmelasercladding/claddingurl";
export default {
  name: "Cmelasercladding",
  dicts: ['zs_cladding_people', 'sys_device_status', 'sys_is_handling', 'sys_quality_result'],
  components: {
    ElFormItem,
    FileUpload,
    CladdingProcess,
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // cmelasercladding表格数据
      cmelasercladdingList: [],
      // 弹出层标题
      title: "",
      //order文件名
      orderfilename: null,
      // 是否显示弹出层
      open: false,
      urlList:{},
      claddingprocess:{},

      predatafilename:null,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        orderId: null,
        claddingPeople: null,
        claddingName: null,
        claddingType: null,
        claddingTech: null,
        deviceStatus: null,
        qualityRecord: null,
        isHandle: null,
        isqualitified: null,
        unnormalRecord: null
      },
      // 表单参数
      form: {},
      // 表单校验（不能为空时添加）
      rules: {
        orderId: [
          { required: true, message: "订单id不能为空", trigger: "blur" }
        ],

        deviceStatus: [
          { required: true, message: "设备状态不能为空", trigger: "blur" }
        ],
        isHandle: [
          { required: true, message: "是否处理不能为空", trigger: "blur" }
        ],
        isqualitified: [
          { required: true, message: "是否合格不能为空", trigger: "blur" }
        ],
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询cmelasercladding列表 */
    getList() {
      this.loading = true;
      listCmelasercladding(this.queryParams).then(response => {
        this.cmelasercladdingList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
      // //获取路由跳转时的传参
      // let orderid = this.$route.query.orderid
      // this.queryParams.orderId = orderid;
      // this.queryParams.oederid = orderid;
      // //获取熔覆处理原始数据
      // listCmelasercladding(this.addDateRange(this.queryParams)).then(response => {
      //   this.claddingprocess = response.rows[0];
      // });
      },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        orderId: null,
        claddingPeople: "0",
        claddingName: null,
        claddingType: null,
        claddingTech: null,
        deviceStatus: 0,
        qualityRecord: null,
        isHandle: 0,
        isqualitified: 0,
        unnormalRecord: null
      };
      this.resetForm("form");
    },
    /** 跳转到详情页 */
    todetail2(row) {
      const orderid = row.orderId
      this.$router.push({ path: '/Detail2', query: {orderid:orderid} })
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加激光熔覆";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getCmelasercladding(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改激光熔覆";
        //获取路由跳转时的传参
        // let orderid = this.$route.query.orderid
        this.queryParams.orderId = this.form.orderId;
        this.queryParams.oederid = this.form.orderId;
        //获取url原始数据
        listCmelasercladding1(this.queryParams).then(response => {
          this.urlList = response.rows[0];
        });
      });
      //获取文件信息
      getFileInformation(this.queryParams).then(response => {
        this.predatafilename = response.predatafilename;
      });
    },
    //claddingprocess文件下载
    getcladdingprocessfile(){
      this.queryParams.resource = this.urlList.claddingprocessUpload;
      download("/cmelasercladding/download/resource", this.queryParams, "熔覆处理文件:"+this.queryParams.orderId + this.predatafilename);
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateCmelasercladding(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addCmelasercladding(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
      this.queryParams.orderId = null;
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除cmelasercladding编号为"' + ids + '"的数据项？').then(function() {
        return delCmelasercladding(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('cmelasercladding/cmelasercladding/export', {
        ...this.queryParams
      }, `cmelasercladding_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
